package com.select.course.controller;

import com.select.course.entity.SchoolClass;
import com.select.course.service.SchoolClassService;
import com.select.course.utils.PageUtils;
import com.select.course.utils.R;
import com.select.course.vo.ClassVo;
import com.select.course.vo.PageVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
@CrossOrigin
@RestController
@RequestMapping("/class")
public class SchoolClassController {
    @Resource
    private SchoolClassService schoolClassService;



    @PostMapping("/getbjinfo")
    public R getClassInfo(@RequestBody PageVo pageVo) {
        PageUtils pageUtils = schoolClassService.getClassPage(pageVo);
        return R.ok().put("data",pageUtils);
    }
    @GetMapping("getclassNamegroup")
    public R getClassGroup() {
        List<SchoolClass> schoolClasses = schoolClassService.getClassNameGroup();

        return R.ok().put("data",schoolClasses);
    }

    @PutMapping("/updatebanji")
    public R updateBanji(@RequestBody ClassVo classVo) {
        schoolClassService.updateBanji(classVo);
        return R.ok();
    }


    @GetMapping("/getclassName/{value}")
    public R getClassName(@PathVariable(value = "value") String name) {
        List<ClassVo> classList = schoolClassService.getClassByMajorName(name);

        return R.ok().put("data",classList);
    }
    @GetMapping("/getbjbybjid/{banjiid}")
    public R getBanJi(@PathVariable String banjiid) {
        ClassVo classVo = schoolClassService.getBanJiByBjId(banjiid);
        return R.ok().put("data",classVo);
    }
    @PostMapping("/addbanji")
    public R addBnaji(@RequestBody ClassVo classVo) {
        R r = schoolClassService.addClass(classVo);
        return r;
    }

    @DeleteMapping("/deletebanji/{id}")
    public R deleteBanJi(@PathVariable Long id) {
        R r = schoolClassService.deleteBanJi(id);
        return r;
    }
}
